/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.bs.controllers;

import com.bs.beans.Lancamento;
import com.bs.extensoesSwing.AbstractGridController;
import com.bs.forms.ConcluirContaForm;
import com.bs.forms.LancamentoForm;
import java.util.Date;

/**
 *
 * @author Bone
 */
public class LancamentoGridController <E> extends AbstractGridController<Lancamento>{

    @Override
    public void novo() {
        Lancamento l = new Lancamento();
        LancamentoForm f = new LancamentoForm(l);
        f.setVisible(true);
        if(l.getId()!= null)adicionarALista(l);
        f = null;
        l = null;
    }

    @Override
    public void alterar() {
        LancamentoForm f = new LancamentoForm(getBeanSelecionado());
        f.setVisible(true);
        f = null;
    }
    
    public void concluir(){
        Lancamento l = getBeanSelecionado();
        ConcluirContaForm c = new ConcluirContaForm();
        Date dataPag = c.getValor();
        if(dataPag == null){
            return;
        }
        l.setDataPagamento(dataPag);
        l.setConcluido(Short.parseShort("1"));
        if(!getEntityManager().getTransaction().isActive()){
            getEntityManager().getTransaction().begin();
        }
        if(l.getId() != null){
            getEntityManager().alterar(l);
        }else{
            getEntityManager().inserir(l);
        }
        getEntityManager().getTransaction().commit();
        getEntityManager().flush();
    }
}
